package com.haixiaoke.saas.enterprise.house.controller;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.ChargeItemDetail;
import com.haixiaoke.saas.house.service.IChargeItemDetailService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋收费项目明细Controller
 *
 * @author xiaolong
 * @date 2023-11-25
 */
@RestController
@RequestMapping("/enterprise/house/chargeItemDetail")
public class EnterpriseChargeItemDetailController extends BaseController {
    @Autowired
    private IChargeItemDetailService chargeItemDetailService;

    /**
     * 查询房屋收费项目明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:detail:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(ChargeItemDetail chargeItemDetail) {
        startPage();
        chargeItemDetail.setTenantId(TenantContext.getTenantId());
        List<ChargeItemDetail> list = chargeItemDetailService.selectChargeItemDetailList(chargeItemDetail);
        return getDataTable(list);
    }

    /**
     * 导出房屋收费项目明细列表
     */
    @PreAuthorize("@ss.hasPermi('business:detail:export')")
    @PostMapping("/export")
    @TenantScope
    public void export(HttpServletResponse response, ChargeItemDetail chargeItemDetail) {
        chargeItemDetail.setTenantId(TenantContext.getTenantId());
        List<ChargeItemDetail> list = chargeItemDetailService.selectChargeItemDetailList(chargeItemDetail);
        ExcelUtil<ChargeItemDetail> util = new ExcelUtil<ChargeItemDetail>(ChargeItemDetail.class);
        util.exportExcel(response, list, "房屋收费项目明细数据");
    }

    /**
     * 获取房屋收费项目明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:detail:query')")
    @GetMapping(value = "/{chargeItemDetailId}")
    public AjaxResult getInfo(@PathVariable("chargeItemDetailId") Long chargeItemDetailId) {
        return success(chargeItemDetailService.selectChargeItemDetailByChargeItemDetailId(chargeItemDetailId));
    }

    /**
     * 新增房屋收费项目明细
     */
    @PreAuthorize("@ss.hasPermi('business:detail:add')")
    @PostMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult add(@RequestBody ChargeItemDetail chargeItemDetail) {
        chargeItemDetail.setTenantId(TenantContext.getTenantId());
        return toAjax(chargeItemDetailService.insertChargeItemDetail(chargeItemDetail));
    }

    /**
     * 修改房屋收费项目明细
     */
    @PreAuthorize("@ss.hasPermi('business:detail:edit')")
    @PutMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult edit(@RequestBody ChargeItemDetail chargeItemDetail) {
        return toAjax(chargeItemDetailService.updateChargeItemDetail(chargeItemDetail));
    }

    /**
     * 删除房屋收费项目明细
     */
    @PreAuthorize("@ss.hasPermi('business:detail:remove')")
    @DeleteMapping("/{chargeItemDetailIds}")
    @TenantScope
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] chargeItemDetailIds) {
        return toAjax(chargeItemDetailService.deleteChargeItemDetailByChargeItemDetailIds(chargeItemDetailIds));
    }
}
